package com.ellecity06.cwhiskymall.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.common.ktx.load
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.response.SearchDiscoveryResponse
import com.ellecity06.cwhiskymall.databinding.ItemHotSearchTopBinding

/**
 * @author ellecity06
 * @time 2024/11/1 18:49
 * @des 热门搜索顶部
 */
class SearchHotTopAdapter : BaseAdapter<SearchDiscoveryResponse.HotSearchSpuVo, ItemHotSearchTopBinding>() {
    override fun inflateBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemHotSearchTopBinding {
        return ItemHotSearchTopBinding.inflate(layoutInflater, parent, false)
    }

    override fun convert(
        binding: ItemHotSearchTopBinding,
        position: Int,
        item: SearchDiscoveryResponse.HotSearchSpuVo
    ) {
        binding.tvGoodName.text = item.spuName
        binding.tvSaleCount.text = item.spuTitle
        binding.ivGood.load(context, item.mainImage)
        when(position){
            0 ->{
                binding.ivBadge.visibility = View.VISIBLE
                binding.ivBadge.setImageResource(R.mipmap.icon_hot_search_sort1)
            }
            1 ->{
                binding.ivBadge.visibility = View.VISIBLE
                binding.ivBadge.setImageResource(R.mipmap.icon_hot_search_sort2)
            }
            2 ->{
                binding.ivBadge.visibility = View.VISIBLE
                binding.ivBadge.setImageResource(R.mipmap.icon_hot_search_sort3)
            }
            else ->{
                binding.ivBadge.visibility = View.GONE
            }
        }
    }
}